package com.mihuo.task;

import com.mihuo.config.quartz.QuartzScheduled;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@QuartzScheduled(jobName = "test",groupName = "testGroup",cron = "0 */2 * * * ?")
public class MyQuartzJob implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // 从 context 中可以获取到任务详情、传递的参数等
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        String taskName = dataMap.getString("taskName");
        
        log.info("任务 {} 开始执行，非框架模式可以移除当前定时任务", taskName);
        try {
            // 你的业务逻辑
            log.info("任务 {} 执行成功，非框架模式可以移除当前定时任务", taskName);
        } catch (Exception e) {
            log.error("任务 " + taskName + " 执行失败，非框架模式可以移除当前定时任务", e);
            throw new JobExecutionException(e);
        }
    }
}